package com.aricksm.xuan.activaty02;

import android.util.Log;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by xuan on 16/6/25.
 */
public class LoginNet {

    public static void doLogin(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Config.API_HOST)
                .build();

        LoopBackService service = retrofit.create(LoopBackService.class);

        Call<ResponseBody> call = service.getFirstBlog(2);

        // 用法和OkHttp的call如出一辙,
        // 不同的是如果是Android系统回调方法执行在主线程
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    System.out.println(response.body().string());
                    Log.e("json:",response.body().string());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                t.printStackTrace();
            }
        });


    }
}
